var express = require('express');
var router = express.Router();
var Activity = require('../models/activity.js').activity;

/* get list page. */
router.get('/', function(req, res) {
    var id = req.query.id;
    if (id) {
        Activity.findByID(id, function(error, doc) {
            console.log(doc);
            if (error) {
                 var obj = {
                    error:{
                        code:2,
                        description:'查询失败'
                    }
                }
                res.send(obj);
            } else {
                var result = {
                    id:doc[0]._id,
                    title:doc[0].title,
                    content:doc[0].content,
                    address:doc[0].address,
                    applyCount:doc[0].people,
                    money:doc[0].money,
                    collected:doc[0].collected.length,
                    time:doc[0].time,
                    replayCount:doc[0].commit.length,
                    images:doc[0].images
                }

                var obj = {
                    error: {
                        code:0,
                        description:'查询成功'
                    },
                    data: result
                }
                res.send(obj);
            }
        })
    } else {
        var obj = {
            error:{
                code:1,
                description:'参数错误'
            }
        };
        res.send(obj);
    }
    console.log(obj);

});

module.exports = router;
